﻿#include <occmesh/mesh/mesh.h>

OCCMesh::OCCMesh(const Standard_Boolean theIsAllowOverlapped) : MeshVS_Mesh(theIsAllowOverlapped)
{
    // 拾取选项
    SetMeshSelMethod(MeshVS_MSM_NODES);
    SetDisplayMode(MeshVS_DMF_WireFrame);
    SetHilightMode(MeshVS_DMF_WireFrame);
    SetTransparency(0.4);

    Handle(MeshVS_Drawer) drawer = GetDrawer();
    drawer->SetColor(MeshVS_DA_InteriorColor, Quantity_NOC_GOLD);
    drawer->SetColor(MeshVS_DA_EdgeColor, Quantity_NOC_BROWN4);

    // 不显示顶点和边
    drawer->SetBoolean(MeshVS_DA_DisplayNodes, Standard_False);
    drawer->SetBoolean(MeshVS_DA_ShowEdges, Standard_True);

    // 选取颜色设置
    mySelectionDrawer->SetInteger(MeshVS_DA_MarkerType, Aspect_TOM_BALL);
    mySelectionDrawer->SetColor(MeshVS_DA_MarkerColor, Quantity_NOC_RED);
    mySelectionDrawer->SetDouble(MeshVS_DA_MarkerScale, 5.0);

    mySelectionDrawer->SetColor(MeshVS_DA_BeamColor, Quantity_NOC_RED);
    mySelectionDrawer->SetDouble(MeshVS_DA_BeamWidth, 1.5);

    myHilightDrawer->SetInteger(MeshVS_DA_MarkerType, Aspect_TOM_BALL);
    myHilightDrawer->SetColor(MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80);
    myHilightDrawer->SetDouble(MeshVS_DA_MarkerScale, 5.0);

    myDynHilightDrawer->SetTransparency(0.6);
}

void OCCMesh::AddDataSource(Handle(MeshVS_DataSource) theDS)
{
    // 将顶点添加到可选集
    Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
    const Standard_Integer aLen = theDS->GetAllNodes().Extent();
    for (Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++)
        aNodes->ChangeMap().Add(anIndex);
    SetSelectableNodes(aNodes);
    SetDataSource(theDS);
}

void OCCMesh::AddMeshBuilder()
{
    Handle(MeshVS_MeshPrsBuilder) aBuilder = new MeshVS_MeshPrsBuilder(this);
    AddBuilder(aBuilder, Standard_True);
}